<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var tim1 = '2021-3-2'
    var tim2 = '2021-12-1'

    //比较俩日期大小
    function dateCompare(date1,date2){
        //根据字符串的分隔线不同中间的符号相应变化，如：“-”，“\”等
        var time1 = new Date(date1.replace(/-/g,"/")).getTime();
        var time2 = new Date(date2.replace(/-/g,"/")).getTime();
        console.log(time1,time2)
        // 起始日期大于等于结束日期的时候
        if(time1 >= time2) {
            return true;
        } else {
            return false;
        }
    }

    console.log(dateCompare(tim1,tim2))
</script>
</html>